package com.mes_for_xxxxxx.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mes_for_xxxxxx.entity.Employee;
import com.mes_for_xxxxxx.entity.Processflow;
import com.mes_for_xxxxxx.entity.dto.LoginDTO;
import com.mes_for_xxxxxx.service.IEmployeeService;
import com.mes_for_xxxxxx.service.IProcessflowService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

/**
 * @author LJK
 * @description
 * @date 2024/9/15
 */
@Controller
@Slf4j
public class TemplateController {
    @Autowired
    IEmployeeService employeeService;
    @Autowired
    IProcessflowService processflowService;

    @RequestMapping("/login/{id}")
    public ModelAndView login(@PathVariable Integer id){
        ModelAndView modelAndView = new ModelAndView();
        LoginDTO login = employeeService.login(id);
        Employee employee = employeeService.getById(id);
        String roomCode = employee.getRoomCode();
        QueryWrapper<Processflow> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("next_room_code",roomCode);
        queryWrapper.eq("status",-1);
        queryWrapper.last("limit 5");
        List<Processflow> list = processflowService.list(queryWrapper);

        modelAndView.addObject("login",login);
        modelAndView.addObject("processflow",list);
        modelAndView.setViewName("showPages");
        log.info("{}的用户登录成功了",id);
        return modelAndView;
    }

    @RequestMapping("/accpet")
    public ModelAndView index(@RequestBody List<Integer> ids){

        return new ModelAndView("index");
    }

}
